<?php

namespace app\common\model\mysql;

use think\Model;

class SGoodsImage extends Model
{
    //批量插入商品与轮播图关联表数据
    public function insertAllGoodsImage($images,$goodsId,$order_num = 0){
        $data = [];
        foreach ($images as $image) {
            $order_num++;
            $data[] = [
                'image_url'=> $image,
                'goods_id' => $goodsId,
                'order_num'=> $order_num,
            ];
        }
        return $this->insertAll($data);
    }

    public function getImages($goodsId){
        $order = [
            "order_num" =>"asc",
        ];
        $where = [
            ['goods_id', '=', $goodsId]
        ];
        $result = $this->where($where)->order($order)->column("image_url");
        return $result;
    }

    /**
     * 删除商品图片数据信息
     * @param $ids
     * @return bool
     */
    public function deleteImageIds($id){
        if(empty($id)){
            return false;
        }
        $where = [
            ['goods_id', '=', $id]
        ];
        $result = $this->where($where)->delete();
        return $result;
    }
}
